
* REPLICATION CODE: JENNINGS & WLEZIEN, 'THE COMPARATIVE TIMELINE OF ELECTIONS', AMERICAN JOURNAL OF POLITICAL SCIENCE *

* FIGURE S1. Adjusted R-Squareds, 900 days

*********************************************************************************************
** MULTIPLE IMPUTATION/BOOTSTRAP - ALL ELECTIONS - VOTE = POLLS *****************************
*********************************************************************************************

use LONG_MI.dta, clear

gen adjrsq=.
gen se_adjrsq=.

foreach x of numlist 1/900 {
quietly mi estimate, cmdok: mybstrpadjr2 vote_ poll_ if daysbeforeED==`x'
matrix bts = e(b_mi)
scalar bt = bts[1,1]
replace adjrsq=bt in `x'
matrix bts = e(V_mi)
scalar bt = bts[1,1]
replace se_adjrsq=sqrt(bt) in `x'
ereturn clear
}

*********************************************************************************************
** OUTPUT/FORMAT THE TIMELINE DATASET *******************************************************
*********************************************************************************************

keep adjrsq se_adjrsq
gen daysbeforeED=_n

drop if adjrsq == .
mi xtset, clear 
sort daysbeforeED

gen adjrsq_min95=adjrsq+se_adjrsq
gen adjrsq_max95=adjrsq-se_adjrsq

save MI_ALL_ADJRSQ.dta, replace

*********************************************************************************************
** MULTIPLE IMPUTATION/BOOTSTRAP - ALL ELECTIONS - VOTE = POLLS + PARTY *********************
*********************************************************************************************

use LONG_MI.dta, clear

drop if daysbeforeED>900
gen _parXcou_ = countryid+(partyid/100)

gen adjrsq=.
gen se_adjrsq=.

foreach x of numlist 1/900 {
quietly mi estimate, cmdok: mybstrpadjr2areg vote_ poll_ if daysbeforeED==`x'
matrix bts = e(b_mi)
scalar bt = bts[1,1]
replace adjrsq=bt in `x'
matrix bts = e(V_mi)
scalar bt = bts[1,1]
replace se_adjrsq=sqrt(bt) in `x'
ereturn clear
}

*********************************************************************************************
** OUTPUT/FORMAT THE TIMELINE DATASET *******************************************************
*********************************************************************************************

keep adjrsq se_adjrsq
gen daysbeforeED=_n

drop if adjrsq == .
mi xtset, clear 
sort daysbeforeED

gen adjrsq_min95=adjrsq+se_adjrsq
gen adjrsq_max95=adjrsq-se_adjrsq

save MI_P_ALL_ADJRSQ.dta, replace

****** SUPPLEMENTARY FIGURE S3.1 **************************************************************
*Adjusted R-Squareds Predicting the Party Vote Share from the Poll Share, By Date in Election Cycle�Pooling all Elections

use MI_ALL_ADJRSQ.dta, clear
rename adjrsq all_adjrsq
rename adjrsq_min95 all_adjrsq_min95
rename adjrsq_max95 all_adjrsq_max95
drop se_adjrsq
sort daysbeforeED
save MI_ALL_ADJRSQ.dta, replace

use MI_P_ALL_ADJRSQ.dta, clear
rename adjrsq p_all_adjrsq
rename adjrsq_min95 p_all_adjrsq_min95
rename adjrsq_max95 p_all_adjrsq_max95
drop se_adjrsq
sort daysbeforeED
save MI_P_ALL_ADJRSQ.dta, replace

merge daysbeforeED using MI_ALL_ADJRSQ.dta

* 
twoway /*
*/  || line all_adjrsq daysbeforeED if daysbeforeED<900, /*
*/  clpattern(solid) clcolor(black) clwidth(medthick)  /* 
*/  || line p_all_adjrsq daysbeforeED if daysbeforeED<900, /*
*/  clpattern(dash) clcolor(black) clwidth(medthick)  /* 
*/  || line all_adjrsq_min95 daysbeforeED if daysbeforeED<900,  /*
*/  clpattern(dot) clcolor(black) clwidth(medium) /*
*/  || line all_adjrsq_max95 daysbeforeED if daysbeforeED<900,  /*
*/  clpattern(dot) clcolor(black) clwidth(medium) /*
*/  || line p_all_adjrsq_min95 daysbeforeED if daysbeforeED<900,  /*
*/  clpattern(dot) clcolor(black) clwidth(medium) /*
*/  || line p_all_adjrsq_max95 daysbeforeED if daysbeforeED<900,  /*
*/  clpattern(dot) clcolor(black) clwidth(medium) /*
*/  , scheme(s2mono) graphregion(color(white)) /*
*/  xtitle("Days Until Election") /*
*/  title("") /*
*/  ylabel(0(.1)1, gmax angle(horizontal)) /*
*/  ytick(0(.1)1) /*
*/  ytitle(Adjusted R-Squared) /*
*/  xlabel(0(100)900) /*
*/  xscale(reverse) xscale(titlegap(2)) /*
*/  legend(order(1 "Without Party Controls" 2 "With Party Controls") /*
*/  rows(1) /*
*/  size(medsmall))

graph export FigS1.tif
